﻿using DatabaseModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GuiImporter.Extensions;
using System.IO;

namespace GuiImporter
{
    public partial class GuiImporter : Form
    {
        private FolderBrowserDialog folderBrowserDialog;
        private OpenFileDialog openFileDialog;

        public GuiImporter()
        {
            InitializeComponent();
            folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
        }

        private void button1_Click(object sender, EventArgs e) {
            if (string.IsNullOrEmpty(txtBasePath.Text)) {
                MessageBox.Show("Please choose a base path!");
                return;
            }
            if (string.IsNullOrEmpty(txtLogFilePath.Text)) {
                txtLogFilePath.Text = Path.Combine(txtBasePath.Text, "Logbook_Import.log");
            }


            try {
                LogBookImporter.Implementation.LogBookImporter importer = new LogBookImporter.Implementation.LogBookImporter();
                int entriesImporter = importer.Import(txtBasePath.Text, txtLogFilePath.Text);
                MessageBox.Show(string.Format("{0} logbook entries imported!", entriesImporter));
            }
            catch (Exception exception) {
                string message = exception.GetaAllMessages();
                
                MessageBox.Show(message);
            }
        }

        private void btnBrowseFolder_Click(object sender, EventArgs e) {
            // Show the FolderBrowserDialog.
            DialogResult result = folderBrowserDialog.ShowDialog();
            if (result == DialogResult.OK) {
                txtBasePath.Text = folderBrowserDialog.SelectedPath;
            }
        }

        private void btnChooseLogFle_Click(object sender, EventArgs e) {
            DialogResult result = folderBrowserDialog.ShowDialog();
            if (result == DialogResult.OK) {
                txtLogFilePath.Text = Path.Combine(folderBrowserDialog.SelectedPath, "Logbook_Import.log");
            }
        }



    }
}
